<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>牛只管理</title>
		<link href="css/new_file.css" rel="stylesheet" type="text/css">
		<link href="css/mui.picker.min.css" rel="stylesheet" type="text/css">
		<link href="css/mui.min.css" rel="stylesheet" type="text/css">
		<script charset="UTF-8" src="js/config.js"></script>
		<script charset="UTF-8" src="js/testActivityName.js"></script>
		<script charset="UTF-8" src="js/core.js"></script>
		<script charset="UTF-8" src="js/cipher-core.js"></script>
		<script charset="UTF-8" src="js/tripledes.js"></script>
		<script charset="UTF-8" src="js/mode-ecb.js"></script>
		<script src="js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="js/zepto.min.js"></script>
		<script type="text/javascript" src="js/spin.min.js"></script>
		<script charset="UTF-8" src="js/mui.min.js"></script>
		<script src="js/echarts.min.js"></script>
		<script charset="UTF-8" src="js/simple.tool.js"></script>
		<script charset="UTF-8" src="js/mui.picker.min.js"></script>
	</head>

	<body>

		<div class="head-zhjf">
			<img src="images/fanhui@3x.png" class="ryjk-tx" onclick="fanhuinie()" >
			<p style="color: white;">添加牛只</p>
		</div>

		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">奶牛编号</div>
			</div>
			<div class="moban-lb-r">
				<input type="text" id="cowCode" onfocus="if(value==defaultValue){value='';this.style.color='#616573'}" onblur="if(!value){value=defaultValue;this.style.color='#dee3f0'}" class="shuru-jine">
			</div>
			<div class="clear"></div>
		</div>

		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">出生日期</div>
			</div>
			<div class="moban-lb-r">
				<input id="birthday" type="text" onfocus=this.blur() onclick="dtPicker('birthday')" placeholder="请选择">
			</div>
			<div class="clear"></div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">产犊日期</div>
			</div>
			<div class="moban-lb-r">
				<input  id="deliveryDate" type="text" onfocus=this.blur() onclick="dtPicker('deliveryDate')" placeholder="请选择">
			</div>
			<div class="clear"></div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">上次配种日期</div>
			</div>
			<div class="moban-lb-r">
				<input  id="Last_mating" style=" margin-top: 1px;" type="text" onfocus=this.blur() onclick="dtPicker('Last_mating')" placeholder="请选择">
			</div> 
			<div class="clear"></div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">繁殖状态</div>
			</div>
			<div class="moban-lb-r">
				<select id="reproductive_status" style="/* display: table-cell; */vertical-align: middle;text-align: left;margin-top: 11px;">
					<option >无记录</option>
					<option value="空怀">空怀</option>
					<option value="适配空怀">适配空怀</option>
					<option value="已配待检">已配待检</option>
					<option value="参配已孕">参配已孕</option>
				</select>
			</div>
			<div class="clear"></div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">牛舍</div>
			</div>
			<div class="moban-lb-r">
				<select id="noApplicationRecord">

				</select>
			</div>

			<div class="clear"></div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">设备编号</div>
			</div>
			<div class="moban-lb-r">
				<p id="deviceSN" onclick="deviceSNBut()" type="text" value="请选择" onfocus="if(value==defaultValue){value='';this.style.color='#616573'}" onblur="if(!value){value=defaultValue;this.style.color='#dee3f0'}" style="color:#cdcdcd;margin-top: 10px;    color: inherit" class="shuru-jine"></p>
			</div>
			<div class="clear"></div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">类型</div>
			</div>
			<div class="moban-lb-r">
				<select id="cowTypes">

				</select>
			</div>
			<div class="clear"></div>
		</div>
		
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">生理类型</div>
			</div>
			<div class="moban-lb-r">
				<select id="cowPhysiologyID">

				</select>
			</div>
			<div class="clear"></div>
		</div>
		
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">状态</div>
			</div>
			<div class="moban-lb-r">
				<select id="statuss">

				</select>
			</div>
			<div class="clear"></div>
		</div>
		<!-- <div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">耳号1</div>
			</div>
			<div class="moban-lb-r">
				<input id="overbiStr1"  type="text" value="选填" onfocus="if(value==defaultValue){value='';this.style.color='#616573'}" onblur="if(!value){value=defaultValue;this.style.color='#dee3f0'}" style="color:;margin-top: 2px;" class="shuru-jine">
			</div>
			<div class="clear"></div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">耳号2</div>
			</div>
			<div class="moban-lb-r">
				<input id="overbiStr2"  type="text" value="选填" onfocus="if(value==defaultValue){value='';this.style.color='#616573'}" onblur="if(!value){value=defaultValue;this.style.color='#dee3f0'}" style="color:;margin-top: 2px;" class="shuru-jine">
			</div>
			<div class="clear"></div>
		</div> -->
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">耳号1</div>
			</div>
			<div class="moban-lb-r">
				<input id="overbiStr1"  type="text" placeholder="选填" style="color:;margin-top: 2px;" class="shuru-jine">
			</div>
			<div class="clear"></div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">耳号2</div>
			</div>
			<div class="moban-lb-r">
				<input id="overbiStr2"  type="text" placeholder="选填" style="color:;margin-top: 2px;" class="shuru-jine">
			</div>
			<div class="clear"></div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">怀孕史</div>
			</div>
			<div class="moban-lb-r">
				<select id="cowConceiveData">

				</select>
			</div>
			<div class="clear"></div>
		</div>
		<div class="moban-lb">
			<div class="moban-lb-l">
				<div class="ziduan-mb">品种</div>
			</div>
			<div class="moban-lb-r">
				<select id="cowVarietyData">

				</select>
			</div>
			<div class="clear"></div>
		</div>

		<div class="tijiao" style="position: static;">
			<button type="button" class="tijiao-btn" onclick="CowSubmission()">提交</button>

		</div>
		<script>
			cowVarietyInterface1() 
			var date = new Date();
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if(month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if(strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
			var currentdate = "Cow" + date.getFullYear() + month + strDate + date.getHours() + date.getMinutes() + date.getSeconds();
			$('#cowCode').val(currentdate);

			var noApplicationRecord = document.getElementById('noApplicationRecord');
			var cowTypes = document.getElementById('cowTypes');
			var statuss = document.getElementById('statuss');
			var cowPhysiologyID = document.getElementById('cowPhysiologyID');
			var cowVarietyData = document.getElementById('cowVarietyData');
			var cowConceiveData = document.getElementById('cowConceiveData');
			
			
			var Cowtianjia = JSON.parse(localStorage.getItem('CowtianjiaData'));
			var cowType = JSON.parse(localStorage.getItem('cowType'));
			var cowStatus = JSON.parse(localStorage.getItem('cowStatus'));
			var cowVarietyArr = JSON.parse(localStorage.getItem('cowVarietyArr'));
			var cowConceiveArr = JSON.parse(localStorage.getItem('cowConceiveArr'));
			var cowPhysiology = JSON.parse(localStorage.getItem('cowPhysiology'));
			
			function setDiv(item) {
				var div = '<select><option id="' + item.houseID + '">' +
					item.houseName +
					'</option></select>'
				return div
			}

			function setDiv1(item) {
				var div = '<select><option id="' + item.cowTypeID + '">' +
					item.cowType +
					'</option></select>'
				return div
			}

			function setDiv2(item) {
				var div = '<select><option id="' + item.statusID + '">' +
					item.status +
					'</option></select>'
				return div
			}
			function setDiv3(item) {
				var div = '<select><option id="' + item.cowVarietyID + '">' +
					item.cowVariety +
					'</option></select>'
				return div
			}
			function setDiv4(item) {
				var div = '<select><option id="' + item.cowConceiveID + '">' +
					item.cowConceive  +
					'</option></select>'
				return div
			}
			function setDiv5(item) {
				var div = '<select><option id="' + item.cowPhysiologyID + '">' +
					item.cowPhysiology +
					'</option></select>'
				return div
			}

			function getnoApplicationData() {
				var html = ''
				for(var i = 0; i < Cowtianjia.length; i++) {
					html += setDiv(Cowtianjia[i])
				}
				noApplicationRecord.innerHTML = html
			}

			function getnoApplicationData1() {
				var html = ''
				for(var i = 0; i < cowType.length; i++) {
					html += setDiv1(cowType[i])
				}
				cowTypes.innerHTML = html
			}

			function getnoApplicationData2() {
				var html = ''
				
				html += setDiv2(cowStatus[0])
				
				statuss.innerHTML = html
			}
			function getnoApplicationData3() {
				var html = ''
				for(var i = 0; i < cowVarietyArr.length; i++) {
					html += setDiv3(cowVarietyArr[i])
				}
				cowVarietyData.innerHTML = html
			}
			function getnoApplicationData4() {
				var html = ''
				for(var i = 0; i < cowConceiveArr.length; i++) {
					html += setDiv4(cowConceiveArr[i])
				}
				cowConceiveData.innerHTML = html
			}
			function getnoApplicationData5() {
				var html = ''
				for(var i = 0; i < cowPhysiology.length; i++) {
					html += setDiv5(cowPhysiology[i])
				}
				cowPhysiologyID.innerHTML = html
			}
			window.onload = getnoApplicationData();
			window.onload = getnoApplicationData1();
			window.onload = getnoApplicationData2();
			window.onload = getnoApplicationData3();
			window.onload = getnoApplicationData4();
			window.onload = getnoApplicationData5();

			var CattleDeviceSN = JSON.parse(localStorage.getItem('CattleDeviceSN'));
			
			var CattleNumber = JSON.parse(localStorage.getItem('CattleNumber'));
			if(CattleNumber == 100) {
				if (CattleDeviceSN != null) {
					var str = CattleDeviceSN.deviceCode;
				}
				var str1 = JSON.parse(localStorage.getItem('cowCodeNumber'));
				var str2 = JSON.parse(localStorage.getItem('birthdayNumber'));
				var str3 = JSON.parse(localStorage.getItem('noApplicationRecordNumber'));
				var str4 = JSON.parse(localStorage.getItem('deviceSNNumber'));
				var str5 = JSON.parse(localStorage.getItem('cowTypeNumber'));
				var str6 = JSON.parse(localStorage.getItem('statusNumber'));
				var str7 = JSON.parse(localStorage.getItem('overbiString1'));
				var str8 = JSON.parse(localStorage.getItem('overbiString2'));
				var str9 = JSON.parse(localStorage.getItem('cowVarietyStr'));
				var str10 = JSON.parse(localStorage.getItem('cowConceiveStr'));
				var str11 = JSON.parse(localStorage.getItem('cowPhysiologyIDNumber'));
				var str12= JSON.parse(localStorage.getItem('Last_matingNumber'));
				var str13 = JSON.parse(localStorage.getItem('reproductive_statusNumber'));
				var str14= JSON.parse(localStorage.getItem('deliveryDateNumber'));
				$("#deliveryDate").val(str14);
				$("#reproductive_status").val(str13);
				$("#Last_mating").val(str12);
				$("#cowCode").val(str1);
				$("#birthday").val(str2);
				$("#noApplicationRecord").val(str3);
				$("#deviceSN").html(str);
				$("#cowTypes").val(str5);
				$("#statuss").val(str6);
				$("#overbiStr1").val(str7);
				$("#overbiStr2").val(str8);
				$("#cowConceiveData").val(str9);
				$("#cowVarietyData").val(str10);
				$("#cowPhysiologyID").val(str11);
			}

			function deviceSNBut() {
				localStorage.setItem('CattleNumber', JSON.stringify(100));
				localStorage.setItem('cowCodeNumber', JSON.stringify($("#cowCode").val()));
				localStorage.setItem('birthdayNumber', JSON.stringify($("#birthday").val()));
				localStorage.setItem('reproductive_statusNumber', JSON.stringify($("#reproductive_status").val()));
				localStorage.setItem('Last_matingNumber', JSON.stringify($("#Last_mating").val()));
				localStorage.setItem('deliveryDateNumber', JSON.stringify($("#deliveryDate").val()));
				localStorage.setItem('noApplicationRecordNumber', JSON.stringify($("#noApplicationRecord").val()));
				localStorage.setItem('deviceSNNumber', JSON.stringify($("#deviceSN").val()));
				localStorage.setItem('cowPhysiologyIDNumber', JSON.stringify($("#cowPhysiologyID").val()));
				localStorage.setItem('cowTypeNumber', JSON.stringify($("#cowTypes").val()));
				localStorage.setItem('statusNumber', JSON.stringify($("#statuss").val()));
				localStorage.setItem('overbiString1', JSON.stringify($("#overbiStr1").val()));
				localStorage.setItem('overbiString2', JSON.stringify($("#overbiStr2").val()));
				localStorage.setItem('cowConceiveStr', JSON.stringify($("#cowConceiveData").val()));
				localStorage.setItem('cowVarietyStr', JSON.stringify($("#cowVarietyData").val()));
//				localStorage.setItem('cowConceiveStr', JSON.stringify(100));
				equipments();
			}
			function fanhuinie(){
				localStorage.setItem('CattleNumber', JSON.stringify(0));
				Cattle1();
			}
			//奶牛品种接口
			function cowVarietyInterface1() {
				var keys = JSON.parse(localStorage.getItem('key'));
				var map = {};
				map.key = keys;
				map.phoneType = "android";
				map.language = "zh";
				var jsonStr = JSON.stringify(map);
				showDialog();
				var ajaxTimeoutTest = $.ajax({
					type: "POST",
					url: url_prefix + "cowVariety",
					dataType: 'JSON',
					timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					success: function(data) {
						dismissDialog();
						var str1 = decryptByDESModeEBC(data["result"]); //解密
						var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
						var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str2); //转JSON字符串
						var aa = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							localStorage.setItem('cowVarietyArr', JSON.stringify(bb.data));
							cowConceiveInterface1();
						} else {
							mui.alert(bb.head.info);
						}
					},
					complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
						　　　　
						dismissDialog();
						if(status == 'timeout') { //超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();　　　　　
							mui.alert("网络请求超时...");　　　　
						}　　
					}
				});
			}
			//奶牛怀孕史接口
			function cowConceiveInterface1() {
				var keys = JSON.parse(localStorage.getItem('key'));
				var map = {};
				map.key = keys;
				map.phoneType = "android";
				map.language = "zh";
				var jsonStr = JSON.stringify(map);
				showDialog();
				var ajaxTimeoutTest = $.ajax({
					type: "POST",
					url: url_prefix + "cowConceive",
					dataType: 'JSON',
					timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					success: function(data) {
						dismissDialog();
						var str1 = decryptByDESModeEBC(data["result"]); //解密
						var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
						var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str2); //转JSON字符串
						var aa = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							localStorage.setItem('cowConceiveArr', JSON.stringify(bb.data));
							cowType1()
			
						} else {
							mui.alert(bb.head.info);
						}
					},
					complete: function(XMLHttpRequest, status) { //请求完成后最终执行参数
						　　　　
						dismissDialog();
						if(status == 'timeout') { //超时,status还有success,error等值的情况
							ajaxTimeoutTest.abort();　　　　　
							mui.alert("网络请求超时...");　　　　
						}　　
					}
				});
			}
			//奶牛类型接口
			function cowType1() {
			
				var keys = JSON.parse(localStorage.getItem('key'));
				var map = {};
				map.key = keys;
				map.phoneType = "android";
				map.language = "zh";
				var jsonStr = JSON.stringify(map);
				
				showDialog();
				$.ajax({
					type: "POST",
					url: url_prefix + "cowType",
					dataType: 'JSON',
					timeout: 10000,
					data: {
						'request': encryptByDES(jsonStr)
					},
					success: function(data) {
						var str1 = decryptByDESModeEBC(data["result"]); //解密
						var params = str1.replace(/\+/g, " "); //去掉字符串里的+号
						var str2 = UTFTranslate.ReChange(chineseFromUtf8Url(params)); //转utf8
						var datas = JSON.stringify(str2); //转JSON字符串
						var aa = datas.replace(/\\n/g, " "); //去掉换行
						var objs = eval('(' + aa + ')');
						var bb = eval('(' + objs + ')');
						if(bb.head.status == 1) {
							localStorage.setItem('cowType', JSON.stringify(bb.data));
							
							
						} else {
							mui.alert(bb.head.info);
						}
					}
				});
			
			}
		</script>
	</body>

</html>